package com.changgou.system.filter;

/**
 * @author lqq
 * @date 2020-02-25 20:19
 */

import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.server.RequestPath;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;

/**
 * 获取客户端的访问url
 */
@Component
public class UrlFilter implements GlobalFilter, Ordered {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        //获取客户端的url访问
        System.out.println("第二个过滤器");
        ServerHttpRequest request = exchange.getRequest();
        RequestPath path = request.getPath();
        System.out.println("path = " + path);
        //过滤器放行
        return chain.filter(exchange);
    }

    @Override
    //过滤器的执行优先级,返回值越小,执行优先级越高
    public int getOrder() {
        return 2;
    }
}
